package com.spancer.contentcenter.service;

import com.spancer.contentcenter.dao.ShareMapper;
import com.spancer.contentcenter.domain.dto.content.ShareDTO;
import com.spancer.contentcenter.domain.dto.user.UserDTO;
import com.spancer.contentcenter.domain.entity.Share;
import com.spancer.contentcenter.feignclient.UserCenterFeignClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * author by: mars
 * Date: 2020/8/5 9:01
 * Description:
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShareService {

    private final ShareMapper shareMapper;
    private final UserCenterFeignClient userCenterFeignClient;
    private final RocketMQTemplate rocketMQTemplate;

    // 根据id获取分享详情
    public ShareDTO findById(Integer id){
        Share share = shareMapper.selectByPrimaryKey(id);
        // 获取发布人id
        Integer userId = share.getUserId();
        // feign
        UserDTO userDTO = userCenterFeignClient.findById(userId);
        ShareDTO shareDTO = new ShareDTO();
        BeanUtils.copyProperties(share,shareDTO);
        shareDTO.setWxNickname(userDTO.getWxNickname());

        rocketMQTemplate.convertAndSend("contentTest",shareDTO);
        return  shareDTO;
    }


}
